home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Dis-Appearance / source code / INIT.c next >
Encoding:
C/C++ Source or Header  |  1997-06-26  |  2.5 KB  |  128 lines  |  [TEXT/CWIE]

  1. #define OLDROUTINENAMES 0
  2. #define OLDROUTINELOCATIONS 0
  3. #define SystemSevenFiveOrLater 1
  4. /* #include files */
  5.  
  6. #include <QuickDraw.h>
  7. #include <Memory.h>
  8. #include <Resources.h>
  9. #include <OSUtils.h>
  10. #include <Traps.h>
  11. #include <Gestalt.h>
  12. #include <A4Stuff.h>
  13. #include <SetupA4.h>
  14.  
  15. /* #defines */
  16. #define assert(i) if ((i) DebugStr("\p;printf \"assertion failed file %s line %d\" __FILE__, __LINE__")
  17.  
  18. #define kINITid            0
  19. #define kICONid            128
  20. #define kSuccessid        130
  21. #define kFailid            131
  22.  
  23. pascal void ShowIcon7(short iconId, Boolean advance);
  24. void InitMask(unsigned char *theMask);
  25.  
  26. /* RGBBackColor patch stuff */
  27.  
  28. pascal void RGBBackColorPatch(const RGBColor *color);
  29.  
  30. typedef pascal void (*RGBBackColorProc)(const RGBColor *color);
  31. RGBBackColorProc    gOldRGBBackColorAddr;
  32.  
  33. /* globals */
  34.  
  35. OSType    gIconTypes[] = {
  36.     'ICN#',
  37.     'ics#',
  38.     'icl8',
  39.     'icl4',
  40.     'ics8',
  41.     'ics4'
  42. };
  43. #define kICONArraySize    (sizeof(gIconTypes)-sizeof(OSType))
  44.  
  45. unsigned char ICN[(32/8)*32];
  46. unsigned char ics[(16/8)*16];
  47. unsigned char icl8[(32/8)*32*8];
  48. unsigned char ics8[(16/8)*16*8];
  49. unsigned char icl4[(32/8)*32*4];
  50. unsigned char ics4[(16/8)*16*4];
  51.  
  52. unsigned char mask[(32/8)*32];    // maximum size mask used for any of the above.
  53.  
  54. /* main */
  55.  
  56. void main(void)
  57. {
  58.     long    oldA4;
  59.     Handle    h;
  60.     Boolean    goOn = true;
  61.     
  62.     #ifdef USE_DEBUGGER_CALLS
  63.         Debugger();
  64.     #endif
  65.  
  66.     /* set up our A4 context for _this file_ */
  67.     oldA4 = SetCurrentA4();
  68.     RememberA4();
  69.     
  70.     ShowIcon7(kSuccessid, false);
  71.     
  72.     /* detach ourselves */
  73.     h = Get1Resource('INIT', kINITid);
  74.     if (h) DetachResource(h);
  75.     else goOn = false;
  76.         
  77.     /* initialize the globals in _this file_ */
  78.     gOldRGBBackColorAddr = 0L;
  79.         
  80.     if (goOn)
  81.     {
  82.         /* patch RGBBackColor */
  83.         gOldRGBBackColorAddr = (RGBBackColorProc)NGetTrapAddress(_RGBBackColor, ToolTrap);
  84.         NSetTrapAddress((UniversalProcPtr)RGBBackColorPatch, _RGBBackColor, ToolTrap);
  85.     }
  86.     
  87.     if (goOn) ShowIcon7(kSuccessid, true);
  88.     else ShowIcon7(kFailid, true);
  89.     
  90.     /* restore the a4 world */
  91.     SetA4(oldA4);
  92. }
  93.  
  94.  
  95. /* RGBBackColorPatch */
  96.  
  97. pascal void
  98. RGBBackColorPatch(const RGBColor *color)
  99. {
  100.     long    oldA4;
  101.     RGBColor noGrey;
  102.     
  103.     #ifdef USE_DEBUGGER_CALLS
  104.         Debugger();
  105.     #endif
  106.     
  107.     /* use the global data in _this file_ */
  108.     oldA4 = SetUpA4();
  109.     
  110.     noGrey.red = noGrey.green = noGrey.blue = 0xFFFF;
  111.  
  112.     /* a _useful_ hack would check that you are in the Finder (check CurApName) */
  113.     
  114.     if ((color->red == 0xDDDD) && (color->green == 0xDDDD) && (color->blue == 0xDDDD))
  115.     {
  116.         gOldRGBBackColorAddr(&noGrey);
  117.     }
  118.     else
  119.     {
  120.         /* call through to the original RGBBackColor */
  121.         gOldRGBBackColorAddr(color);
  122.     }
  123.     
  124.     /* restore the a4 world */
  125.     RestoreA4(oldA4);
  126. }
  127.  
  128.